<?php
/**
 * User: @lose
 * Date: 2019-09-25
 * Time: 18:00
 */

ini_set('display_errors', 1);
error_reporting(-1);

require_once '/data/wwwroot/g_vendor/autoload.php';


use Doraemon\model\Position\PositionBaseInfo;

$data = PositionBaseInfo::select('*', ['id' => 10064]);

foreach ($data as $info) {
    $item = [];
    if($info['link_type'] == 'hhz://' && strpos($info['link_params'], '{"url":"topic_detail:') !== false) {
        $item['link_type'] = 'hhz://topic_detail';
//        {"url":"topic_detail:{\"topic_id\":\"1004\"}"}
        $item['link_params'] = json_encode(['topic_id' => 1004]);
        var_dump($info);
        PositionBaseInfo::update($item, ['id' => $info['id']]);

        PositionBaseInfo::update(['link_type' => 'hhz://topic_detail', 'link_params' => '{"topic_id":"1004"}'], ['id' => 10064]);
    }


}
die;
foreach ($data as $info) {
    $item = [];
    if($info['link_type']) {

        if($info['link_type'] == 'hhz://') {
            $item['link_params'] = json_encode(['url' => $info['link_params']], JSON_UNESCAPED_UNICODE);
        }

        if($info['link_type'] == 'hhz://photo:') {
            $item['link_type'] = 'hhz://photo';
            $item['link_params'] = json_encode(['note_id' => $info['link_params']]);
        }

        if ($info['link_type'] == 'https://') {
            $item['link_params'] = json_encode(['url' => $info['link_params']]);
        }

        if($info['link_type'] == 'hhz://blank:') {
            $item['link_type'] = 'hhz://blank';
            $item['link_params'] = json_encode(['blank_id' => $info['link_params']]);
        }

        if($info['link_type'] == 'hhz://urlb:') {
            $item['link_type'] = 'hhz://';
            $item['link_params'] = json_encode(['url' => 'urlb:'.base64_decode($info['link_params'])]);
        }

        if($info['link_type'] == 'hhz://article:') {
            $item['link_type'] = 'hhz://article';
            $item['link_params'] = json_encode(['article_id' => $info['link_params']]);
        }

        if($info['link_type'] == 'hhz://guide:') {
            $item['link_type'] = 'hhz://guide';
            $item['link_params'] = json_encode(['guide_id' => $info['link_params']]);
        }

        if(strpos($info['link_type'], 'hhz://topic_detail:') !== false) {
            $info['link_type'] = substr($info['link_type'], 19);
            $info['link_type'] = json_decode($info['link_type'], true);

            $info['link_type']['topic_id'] = $info['link_params'];
            $item['link_params'] = json_encode($info['link_type'], JSON_UNESCAPED_UNICODE);
            $item['link_type'] = 'hhz://topic_detail';
        }

        PositionBaseInfo::update($item, ['id' => $info['id']]);

    }


}